﻿using FluentValidation;
using Sgr.DataCategories.Application.Commands.DataCategoryItem;

namespace Sgr.DataCategories.Application.Validations.DataCategoryItem
{
    public class UpdateCategpryItemCommandValidator : AbstractValidator<UpdateCategpryItemCommand>
    {
        public UpdateCategpryItemCommandValidator()
        {
            RuleFor(command => command.Id)
                .GreaterThan(0).WithMessage("ID必须大于0");

            RuleFor(command => command.DcItemName)
                .NotEmpty().WithMessage("字典项名称不能为空")
                .MaximumLength(100).WithMessage("字典项名称长度不能超过100个字符");

            RuleFor(command => command.Remarks)
                .MaximumLength(100).WithMessage("备注长度不能超过100个字符");

            RuleFor(command => command.OrderNumber)
                .GreaterThanOrEqualTo(0).WithMessage("排序号必须大于或等于0");

            RuleFor(command => command.ParentId)
                .GreaterThan(0).When(x => x.ParentId.HasValue)
                .WithMessage("上级ID必须大于0");
        }
    }
}